package Testes;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import Modelo.Login;

import jdbc.ConnectionFactory;

public class TestaInsereLogin {

	private static Connection cnn;
	private static PreparedStatement stmt;
	private static String sql;	
	
	public static void main(String[] args) throws SQLException {
		Login login = new Login("lala", "lala");
		addLogin(login);
	}

	public static void addLogin(Login login) throws SQLException {
		sql = "INSERT INTO slv_web.tblogin (login, senha) VALUES (?,?)";
		cnn = new ConnectionFactory().getConnection();

		try {
			stmt = cnn.prepareStatement(sql);
			
			stmt.setString(1, login.getLogin());
			stmt.setString(2, login.getSenha());

			stmt.execute();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				cnn.rollback();
			} catch (SQLException e1) {
				System.out.print(e1.getStackTrace());
			}
		} finally {
			stmt.close();
			cnn.close();
		}
	}
}
